<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <button @click="person.age++">加一岁</button>
    <p>姓名:{{person.name}}--年龄:{{person.age}}</p>
    <button @click="isHot=!isHot">点击修改天气</button>
    <p>今天天气真{{isHot?"热啊":"冷啊"}}</p>
    <img :src="url">
  </div>
  <script>
    Vue.config.productionTip = false;

    const vm = new Vue({
      el: "#app",
      data() {
        return {
          isHot: true,
          url: "./re.webp",
          person: {
            name: "laowang",
            age: "20"
          }
        }
      },
      watch: {
        isHot: {
          // 立即监视
          immediate: true,
          // 当isHot改变时handler函数执行
          handler(newValue, oldValue) {
            this.url = newValue ? "./re.webp" : "./leng.gif"
          }
        },
        person: {
          // 深度监视
          deep: true,
          handler() {
            alert("老咯")
          }
        }
      }
    })
  </script>
</body>

</html>